
import
	tango.io.device.Array,
	tango.stdc.stringz,
	tango.io.Stdout ,
	
	tango.math.random.Random,
	tango.net.device.Berkeley,
	tango.net.InternetAddress,
	tango.net.InternetAddress,
	Int	= tango.text.convert.Integer ,
	tango.core.Array ,
	tango.io.device.Array ,
	tango.io.device.File ,
	libeventd.Types ;


void main(){
	WSADATA wd = void;
	WSAStartup (0x0202, &wd);

	auto event_base	= event_base_new();
	// evthread_use_windows_threads();
	auto evdns_base = evdns_base_new(event_base, 0);
	evdns_set_log_fn(&logfn);
	
	evdns_base_config_windows_nameservers(evdns_base);
	
	evdns_base_resolve_ipv4(evdns_base, "baidu.com\0".ptr , 0, &evdns_server_callback, null);
	
	event_base_dispatch(event_base);
}

extern(C):

void logfn(int is_warn,  char *msg) {
	Stdout.formatln("{},{}", is_warn, fromStringz(msg) );
}

void evdns_server_callback(int result, char type, int count, int ttl, void *addresses, void *arg) {
	
	if( result !is 0 ){
		Stdout.formatln("dns query failure result:{}: type:{}", result, type);
		return ;
	}
		
	ubyte* addr	= cast(ubyte*) addresses;
	for( int i =0 ; i < count; i++) {
		Stdout.formatln("ip{} : {}", i+1, (addr + i * 4)[0..4] );
	}
}

